home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / snip9611.zip / WB_FAPND.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  2KB  |  56 lines

  1. /* +++Date last modified: 23-Nov-1996 */
  2.  
  3. /*
  4. ** by: Walter Bright via Usenet C newsgroup
  5. **
  6. ** modified by: Bob Stout based on a recommendation by Ray Gardner
  7. **
  8. ** modified by: David Gersic to deal with binary files
  9. **
  10. ** There is no point in going to asm to get high speed file copies. Since it
  11. ** is inherently disk-bound, there is no sense (unless tiny code size is
  12. ** the goal). Here's a C version that you'll find is as fast as any asm code
  13. ** for files larger than a few bytes (the trick is to use large disk buffers):
  14. */
  15.  
  16. #include <stdlib.h>
  17. #include <io.h>
  18. #include <fcntl.h>
  19. #include "snipfile.h"               /* Contains prototype for fdcopy()  */
  20.  
  21. #if !defined(__ZTC__) && !defined(__TURBOC__)
  22.  #include <sys\types.h>
  23. #endif
  24.  
  25. #include <sys\stat.h>
  26.  
  27. int file_append(char *from, char *to)
  28. {
  29.       int fdfrom,fdto;
  30.       int bufsiz;
  31.  
  32.       fdfrom = open(from,O_RDONLY|O_BINARY,0);
  33.       if (fdfrom < 0)
  34.             return 1;
  35.  
  36.       /* Open R/W by owner, R by everyone else        */
  37.  
  38.       fdto=open(to,O_BINARY|O_CREAT|O_APPEND|O_RDWR,S_IREAD|S_IWRITE);
  39.       if (fdto >= 0)
  40.       {
  41.             if (Success_ == fdcopy(fdfrom, fdto))
  42.             {
  43.                   close(fdto);
  44.                   close(fdfrom);
  45.                   return Success_;
  46.             }
  47.             else
  48.             {
  49.                   close(fdto);
  50.                   remove(to);             /* delete any partial file  */
  51.             }
  52.       }
  53.       close(fdfrom);
  54.       return Error_;
  55. }
  56.